package com.sts.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.sts.bean.Eq_run;
import com.sts.dao.IEq_runDao;

@Service
public class Eq_runService implements IEq_runService {

	
	private Logger log = Logger.getLogger(this.getClass());
	@Resource
	private IEq_runDao runDao ;
	
	@Override
	public boolean addEq_run(Eq_run run) {
		log.debug("eq_run service in");
		
		boolean b = runDao.insterEq_run(run) == 1 ;
		
		
		
		log.debug("eq_run service in");
		return b;
	}

	@Override
	public List<Eq_run> selectEq_run(String eq_id, String car_id,String page1,String limit1,String data1,String day) {
		
		Map<String,Object> map = new HashMap<String,Object>();
		
		
		if(eq_id == null){
			eq_id = "";
		}
		if(car_id == null){
			car_id = "";
		}
		if(data1 == null){
			data1 = "";
		}
		if(day != null && day != "" ){
			data1 = "";
		}if(day == null){
			day = "";
		}
		log.debug("service eq_id"+eq_id);
		log.debug("service car_id"+car_id);
		log.debug("service data1"+data1);
		if(page1 == null){
			page1 = "1" ;
		}
		if(limit1 == null){
			limit1 = "10";
		}
		int page = Integer.parseInt(page1) -1;
		int limit = Integer.parseInt(limit1) ;
		page = page * limit ;			//分页的起始位置
		map.put("eq_id", eq_id);
		map.put("car_id", car_id);
		map.put("page", page);
		map.put("limit", limit);
		map.put("data1",data1) ;
		map.put("day",day) ;
		log.debug("map"+map);
		List<Eq_run> list = new ArrayList<Eq_run>() ;
		list = runDao.selectEq_run(map);
		
		return list;
	}

	@Override
	public int selectSize(String eq_id,String car_id,String data1,String day) {
		int result = 0 ;
		Map<String, Object> map = new HashMap<String, Object>();
		if(eq_id == null){
			eq_id = "" ;
		}
		if(car_id == null){
			car_id = "" ;
		}
		if(data1 == null){
			data1 = "";
		}
		if(day != null && day != "" ){
			data1 = "";
		}if(day == null){
			day = "";
		}
		map.put("eq_id", eq_id);
		map.put("car_id", car_id);
		map.put("data1",data1) ;
		map.put("day",day) ;
		result = runDao.selectSize(map) ;
		return result;
	}

	@Override
	public List<Eq_run> selTemp() {
		List<Eq_run> list = runDao.selectTemp();
		return list;
	}

}
